import torch.nn as nn
import torch
import time
from modules.models.backbones import BuildBackbone
from configs.deeplabv3plus.deeplabv3plus_resnet50os8_RopeGlass import SEGMENTOR_CFG
import copy
from modules.models.segmentors.builder import BuildSegmentor
# # from configs.fcn.fcn_resnet50os16_cityscapes import SEGMENTOR_CFG

device = torch.device('cuda')
# input = torch.randn((2,3,512,512)).to(device=device)
# bigmodeloutput = torch.randn(1,1,628,4096).to(device=device)
# bigmodeloutput = {"bigmodeloutput":bigmodeloutput}
input = torch.randn((2,3,512,1024)).to(device=device)
# model = BuildBackbone(SEGMENTOR_CFG['backbone']).to(device=device)

segmentor = BuildSegmentor(segmentor_cfg=copy.deepcopy(SEGMENTOR_CFG), mode='TRAIN').to(device)
print(segmentor)
res = segmentor(input)
print(res.size())
# for i in res:
#     print(i.size())
# print(model)
# # model.eval()
# # model.to(device)

# iterations = None
# with torch.no_grad():
#     for _ in range(10):
#         model(input)
#     if iterations is None:
#         elapsed_time = 0
#         iterations = 100
#         while elapsed_time < 1:
#             t_start = time.time()
#             for _ in range(iterations):
#                 model(input)
#             elapsed_time = time.time() - t_start
#             iterations *= 2
#         FPS = iterations / elapsed_time
#         iterations = int(FPS * 6)
#     print('=========Speed Testing=========')
#     t_start = time.time()
#     for _ in range(iterations):
#         model(input)
#     elapsed_time = time.time() - t_start
#     latency = elapsed_time / iterations * 1000
# torch.cuda.empty_cache()
# FPS = 1000 / latency
# print(FPS)

# output = model(input)
# # print(SEGMENTOR_CFG)

# # kv =nn.Parameter(torch.zeros(5, 5, 7, 1))
# # print(kv)
# a = 64
# print(len(a))
